package com.fessc.develop.handler.processor.request;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fessc.develop.base.Result;
import com.fessc.develop.entity.dbvo.TOrgConfig;
import com.fessc.develop.entity.comvo.PlatformSyncVo;
import com.fessc.develop.model.enums.EnumResultType;
import com.fessc.develop.model.enums.EnumServiceCode;
import com.fessc.develop.service.interfaces.ITOrgConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Slf4j
@Service
public class ComPlatInfoQueryProcess implements IBaseService {

    @Resource
    private ITOrgConfigService orgConfigService;

    @Override
    public String getServiceCode() {
        return EnumServiceCode.COM_BS0001.toString();
    }

    @Override
    public Result process(JSONObject requestBody) {
        log.info("市场交易平台信息查询请求报文: " + requestBody.toJSONString());
        List<TOrgConfig> orgConfigList = orgConfigService.getOrgConfigByPaymentType("B");
        List<PlatformSyncVo> platSyncVoList = new ArrayList<>();
        for (TOrgConfig orgConfig : orgConfigList) {
            PlatformSyncVo platSyncVo = new PlatformSyncVo();
            platSyncVo.setPlatidS(orgConfig.getPlatidS());
            platSyncVo.setOrgName(orgConfig.getOrgFullName());
            platSyncVoList.add(platSyncVo);
        }
        Result result = new Result(EnumResultType.SUCCESS.getStatusCode(), EnumResultType.SUCCESS.getMsg());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("platInfoArray", platSyncVoList);
        result.setData(jsonObject);
        log.info("市场交易平台信息查询返回报文: " + JSON.toJSONString(result));
        return result;
    }
}
